//
//  NSArray+Swizzling.m
//  RuntimeTest
//
//  Created by Charles on 16/9/27.
//  Copyright © 2016年 Charles. All rights reserved.
//

#import "NSArray+Swizzling.h"
#import <objc/runtime.h>
#import "NSObject+Swizzling.h"


@implementation NSArray (Swizzling)

//+ (void)load{
//    static dispatch_once_t onceToken;
//    dispatch_once(&onceToken, ^{
//        [self swizzleSelector:@selector(lastObject) withSwizzledSelector:@selector(cl_lastObject)];
//    });
//}

- (id)cl_lastObject{
    if (self.count == 0) {
        NSLog(@"%s 数组为空,直接返回nil",__func__);
        return nil;
    }
    return [self cl_lastObject];
}

- (id)delegate{
    return objc_getAssociatedObject(self, @"__delegate_key__");
}

- (void)setDelegate:(id)delegate{
    objc_setAssociatedObject(self, @"__delegate_key__", delegate, OBJC_ASSOCIATION_ASSIGN);
}

@end
